<style scoped>
.p_c1{
    width:50%;float: left;padding-left: 10px;
    span{line-height: 22px;}
}
</style>
<template>
<div>
     <Modal v-model="modal" :title="title" :styles="{width:'500px',top:'20px'}" :mask-closable="false">


     	<div style="margin-top:10px;">
     	  <p style="padding-left:30px;padding-bottom:20px;font-size:13px;">
     	  商品名称:{{data.goodsName}}    <br/>商品数量:{{data.goodsQuantity}}     
     	  <br/>商品总额:{{data.goodsTotalPrice}}</p>
          <Form ref='form1' :model="obj" label-position="right" :rules="ruleValidate" :label-width="100" >
            
            <FormItem label="拆分数量" prop="splitGoodNum">
                <Input  v-model="obj.splitGoodNum" style="width:200px;"></Input>
            </FormItem>
         </Form>  
         <p style="padding-left:30px;font-size:13px;">
         	拆分金额:{{ (obj.splitGoodNum*data.goodsPrice).toFixed(2)}}
         </p>
        </div>       
         <div slot="footer">
             <Button @click="cancel()">关闭</Button>
             <Button @click="sub()" type="primary" :loading="loading">提交</Button>
         </div>
     </Modal>
</div>
</template>
<script>
 export default {
     data (){
         return {
             modal:false,title:'拆分',status:'',loading:false,
             data:{mainVo:{},},
             obj:{splitGoodNum:'',goodGuid:''},
             ruleValidate:{
                 splitGoodNum:[
                     { required: true, message: '拆分数量不能为空', trigger: 'blur' },
                     {validator:(r,v,call)=>{
                     	console.log(r,v,this.data)
                     	if(Number(v)>Number(this.data.goodsQuantity)){
                     		call(new Error('拆分数量不能大于总数'))
                     	}else{
                     		call();
                     	}
                     },trigger:'blur'}
                 ]
             }
         }
     },methods:{
         showdata(params){
         	console.log(params);
            this.obj.goodGuid=params.guid;
            this.obj.splitGoodNum=null;
            this.data=params;
            this.modal=true;
            
            
            
         },
         cancel(){
             this.modal=false;
         },sub(){
             if(this.handleSubmit()){
             	this.loading=true;
             	this.axios.post('/outputinoivce/splitGood',this.obj).then((res)=>{
	                console.log(res);
	                this.modal=false;
	                if(res.errorCode==0){
	                     this.$Message.success(res.message);
	                     this.$emit('refresh')
	                 }else{
	                     //this.$Message.error(res.message);
	                 }
                     this.loading=false;
	                
	                
	            })
             }
            
         },handleSubmit () {
             var a=true;
             this.$refs['form1'].validate((valid) => {
                 if (valid) {
                     //this.$Message.success('Success!');
                 } else {
                     //this.$Message.error('Fail!');
                     a=false;
                 }
             })
             return a;
         }
     },created(){
        //alert('a')
         this.$parent.$on('bus_splitedit', this.showdata);
         
     },beforeDestroy(){
         this.$parent.$off('bus_splitedit',this.showdata)
     }
 }
</script>